import sys

from PyQt4 import QtCore, QtGui

class SortoCounter(QtGui.QWidget):
    
    def __init__(self, parent, number, color, size):
        QtGui.QWidget.__init__(self, parent=parent)
        self._number = number
        self._color = color
        self._size  = size
        if sys.platform == 'win32':
            self._size += 1
            pass
        self.setGeometry(0,0,self._size, self._size)
        return
    
    def _set_color(self, val):
        self._color = val
        return
    
    def _get_color(self):
        return self._color
    
    color = property(_get_color, _set_color)

    def paintEvent(self, event):
        qp = QtGui.QPainter()
        qp.begin(self)
        self._drawBackground(event, qp)
        self._drawNumber(event, qp)
        qp.end()
        return

    def _drawBackground(self, event, qp):
        color = QtGui.QColor(0,0,0)
        color.setNamedColor(self._color)
        qp.setBrush(color)
        corner = 1
        size = self._size - 2
        if sys.platform == 'win32':
            corner = 0
            size = self._size - 1
            pass
        qp.drawEllipse(corner, corner, size, size)
        return

    def _drawNumber(self, event, qp):
        qp.setPen(QtGui.QColor(QtCore.Qt.black))
        qp.setFont(QtGui.QFont('Arial Black', 26))
        qp.drawText(event.rect(), QtCore.Qt.AlignCenter, str(self._number))
        return
    
    pass # End of class SortoCounter
